home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-12-13 | 3.4 KB | 89 lines | [TEXT/ttxt] |
- language: infix-dylan
- module: Online-Insultant
-
- /* Copyright (C) 1994, Apple Computer, Inc. All rights reserved. */
-
- /* This reads the insult out loud, in case the user is illiterate
- *--- I should make this select a higher quality voice
- *--- than the rather crummy default one
- */
-
- // Import the Speech Manager interface
- // I copied the file from Feb 94 Developer CD to the project directory
- define interface
- #include "Speech.h",
- name-mapper: minimal-name-mapping-with-structure-prefix,
- define: {"SystemSevenOrLater"},
- import: {"gestaltSpeechAttr", "gestaltSpeechMgrPresent",
- "SpeakString", "SpeakText", "SpeechBusy",
- "MakeVoiceSpec", "VoiceSpec",
- "NewSpeechChannel", "DisposeSpeechChannel", "SpeechChannel",
- "voiceNotFound",
- // fun stuff for playing around, delete later
- "CountVoices", "GetIndVoice",
- "VoiceDescription", "GetVoiceDescription"},
- type: {"StringPtr" => <Pascal-string>};
- function "SpeakText", argument-type: {textBuf => <C-string>};
- function "NewSpeechChannel", output-argument: chan;
- function "CountVoices", output-argument: numVoices;
- // We'll need Gestalt also
- #include "Gestalt.h",
- name-mapper: minimal-name-mapping-with-structure-prefix,
- // Gestalt was not a trap in System 6
- define: {"SystemSevenOrLater"},
- import: {"Gestalt"};
- function "Gestalt", output-argument: response;
- // We need this so we can free a text-buffer
- #include "memory.h",
- name-mapper: minimal-name-mapping-with-structure-prefix,
- define: {"SystemSevenOrLater"}, // for Gestalt
- import: {"DisposePtr"};
- end interface;
-
- define constant Speech-Available? = method()
- let (err, result) = Gestalt($gestaltSpeechAttr);
- err = 0 & logbit?($gestaltSpeechMgrPresent, result);
- end method;
-
- define constant await-speech-done = method()
- until ( SpeechBusy() = 0 ) end;
- end method;
-
- // This compressed high-quality female voice seems to sound best
- define constant $preferred-voice :: <VoiceSpec> = begin
- let v = make(<VoiceSpec>);
- MakeVoiceSpec(OSType("gala"), 0, v);
- v;
- end;
-
- // returns error code, or if successfully started asynchronous speech, values(chan, text-buffer)
- define constant speak-string = method(string :: <string>, #key synchronous)
- let (err, chan) = NewSpeechChannel($preferred-voice);
- let (err, chan) = if ( err = $voiceNotFound )
- // The preferred voice does not exist, so use the default system voice
- NewSpeechChannel(as(<VoiceSpec>, 0));
- else values(err, chan);
- end if;
- if (err = 0)
- let text-buffer = as(<C-string>, string); // this makes a copy in the heap
- let err = SpeakText(chan, text-buffer, size(string));
- if (err = 0)
- if (synchronous)
- finish-speak-string(chan, text-buffer);
- err;
- else values(chan, text-buffer);
- end if;
- else err;
- end if;
- else err;
- end if;
- end method;
-
- // call this with the values from an asynchronous speak-string
- define constant finish-speak-string = method(chan, text-buffer)
- if (instance?(chan, <SpeechChannel>))
- await-speech-done();
- DisposeSpeechChannel(chan);
- DisposePtr(as(<machine-pointer>, text-buffer));
- end if;
- end method;